# coding=utf-8
"""
# Author : Hunter Oakley
# Time   : 2022/6/9 23:34
# Descripation:自定义的Form
"""

from django import forms
from utils.Bootstrap import BootStrapForm
from utils.encrypt import md5

class LoginForm(BootStrapForm):
    """
    登录的Form
    """
    username = forms.CharField(
        label="用户名",
        required=True,  # 不能为空
        widget=forms.TextInput
    )
    password = forms.CharField(
        label="密码",
        required=True,
        widget=forms.PasswordInput(render_value=True)
    )
    image_code = forms.CharField(
        label="图片验证码",
        required=True,
        widget=forms.TextInput
    )

    def clean_password(self):
        # 获取用户输入的密码，并且进行加密
        pwd = self.cleaned_data.get("password")
        return md5(pwd)


class UpForm(BootStrapForm):
    """
    文件上传的Form
    """
    BootStrapForm.exclude_fileds = ["img"]
    name = forms.CharField(label="姓名",max_length=32)
    age = forms.IntegerField(label="年龄")
    img = forms.FileField(label="头像")













